Project Description¶
In this project, we will write reusable Python functions to standardize validation checks for new user sign-ups in a mobile app. Our goal is to reduce invalid and incomplete sign-up attempts that cause the app to crash. By creating reliable validation code, we will help improve the user experience and make the app more stable.
We are working with a small startup that wants to improve the sign-up process for their main mobile app. Currently, many users enter incorrect or incomplete information when signing up, which leads to app crashes. To solve this, we will create reusable Python functions that check user inputs such as names, emails, and passwords before new accounts are created.
Our task is to write core validation functions that ensure all user data meets minimum requirements. These functions will help catch errors early, prevent crashes, and make the sign-up process smoother. The managers support this approach and have asked us to develop these essential validation tools to improve the overall quality of user registrations. .
Implement a function called validate_name()
¶
# Create a function that validates the input name is a string and greater than 2 characters
def validate_name(name):
# Check that datatype of the variable is string
if type(name) != str:
return False
# Check if character is less than two characters
elif len(name) <= 2:
return False
# Name passed all checks
else:
return True
Implement a function called validate_email()
¶
# list of domains for validating email domain
top_level_domains = [
".org",
".net",
".edu",
".ac",
".gov",
".com",
".io"
]
# Create a function that validates the email is in the correct format
def validate_email(email):
# If the email does not include the @ symbol, return False
if '@' not in email:
return False
# Loop through domain string in the top_level_domains list
for domain in top_level_domains:
# Check if the domain is included in the email
if domain in email:
# If the domain is in the email, return True.
return True
# If code reaches this point, return False to indicate invalid email
return False